<script>
// Upload Image  
var finishUpload = function(){


        var uploadData = jQuery("#upload_target").contents().find('html body').html()
        jQuery("#gallery_items").html(uploadData);
        // alert("Sdfsdfs");

        jQuery("a[href$='gif']").fancybox();
	jQuery("a[href$='jpg']").fancybox();
	jQuery("a[href$='png']").fancybox();
	
	jQuery("a[href$='GIF']").fancybox();
	jQuery("a[href$='JPG']").fancybox();
	jQuery("a[href$='PNG']").fancybox();
	
	jQuery("#image_picture").attr("value", "");
        jQuery("#image_title").attr("value", "");
        
        

};

function TestFileUpload()
{
	if (jQuery("#FormName_File").attr("value") == "")
	{
		alert("Please select a image file to upload !");
		return false;
	}
        loading_area('<%= image_tag "loading_ajax.gif" %>', "#gallery_items", "#gallery_items");
        $.fancybox.close();
	return true;
};

</script>

<script>
function delete_image(id, title, url)
{
		// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
		jQuery( "#dialog:ui-dialog" ).dialog( "destroy" );
		jQuery( "#dialog-title" ).html("Detele image <strong>" + title + "</strong>");	
		jQuery( "#dialog-modal" ).dialog({
			resizable: false,
			height:140,
			modal: true,			
			buttons: {
				"Yes": function() {
					loading_area('<%= image_tag "loading_ajax.gif" %>', "#gallery_items", "#gallery_items");					      
					$( this ).dialog( "close" );
					jQuery.ajax({
					  url: url,
					  type: 'DELETE',
					  success: function (data){
					    jQuery.ajax({
						// jQuery("#gallery_items").html("<%= escape_javascript render(:file => 'images/_small_gallery_items.html.erb') %>");
					    });
					  }
					});
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}

		});
}
</script>


<!-- SMALL GALLERY -->
				<div class="content-box">
					<div class="box-body">
						<div class="box-wrap clear">
							<h2>Image Gallery</h2>					
                                                        <div  id="gallery_items" class="style1">
                                                          <%= render "/images/small_gallery_items" %>								
                                                        </div>
						</div> <!-- end of box-wrap -->
                                                
						<iframe id="upload_target" name="upload_target" src="" style="display: none" ></iframe>
                                                <div style="">
                                                  <h1 style="text-align:center;margin-top: -20px;"><a href="#modal-upload" class="label upload-button blue">UPLOAD IMAGE</a></h1>
                                                  <!-- MODAL WINDOW -->
                                                  <div id="modal-upload" class="modal-window">
                                                          
                                                                                                                       
                                                              <!-- UPLOAD IMAGE -->
                                                              <% form_tag({:controller => "images", :action => 'upload'}, :multipart=>true, :target => 'upload_target', :onSubmit => "return TestFileUpload()" ) do %>
                                                                <h2>Upload Image</h2>
                                                                <p><small><strong>Image name:</strong><br />
                                                                  <input id="image_title" type="text" name="image[title]"  value="" /><br />
                                                                  <strong>Location:</strong><br /><input id="image_picture" type="file" name="image[picture]"  value="" />
                                                                  </p>
                                                                  <p><input id="FormName_Button" class="button blue fl-space" type="submit" value="Upload" /></p>
                                                                  <input type="hidden" name="image[event_id]" value="<%= @event.id %>" />
                                                                </small></p>
                                                              <% end %>
                                                              <!-- END UPLOAD -->
                                                              
                                                          
                                                  </div>
                                                  
                                                </div>
					</div> <!-- end of box-body -->

				</div> <!-- end of content-box -->
